﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using CodeFarmer.Model.Entities;

namespace CodeFarmer.DataAccess
{

    public class CodeFarmerInitializer : DropCreateDatabaseIfModelChanges<CodeFarmerContext>
    {
        protected override void Seed(CodeFarmerContext context)
        {
            //构造初始化数据

            DateTime dt = DateTime.Now;

            var authors = new List<User>(){
                new User(){ ID=1, NickName="NO1", UserName="1", Email="NO1@CodeFarmer.cn", PassWord="1", CreateTime=dt, LastLoginTime=dt, State=0},
                new User(){ ID=2, NickName="NO2", UserName="2", Email="NO2@CodeFarmer.cn", PassWord="1", CreateTime=dt, LastLoginTime=dt, State=0},
                new User(){ ID=3, NickName="NO3", UserName="3", Email="NO3@CodeFarmer.cn", PassWord="1", CreateTime=dt, LastLoginTime=dt, State=0},
                new User(){ ID=4, NickName="NO4", UserName="4", Email="NO4@CodeFarmer.cn", PassWord="1", CreateTime=dt, LastLoginTime=dt, State=0},
                new User(){ ID=5, NickName="NO5", UserName="5", Email="NO5@CodeFarmer.cn", PassWord="1", CreateTime=dt, LastLoginTime=dt, State=0},
            };
            authors.ForEach(t => context.User.Add(t));
            context.SaveChanges();

            var articles = new List<Article>(){
                new Article(){ ID=10, AuthorID=1, CreateTime=dt, State=0, Content="c10", EnableCommnet=true, Title="t10", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=11, AuthorID=1, CreateTime=dt, State=0, Content="c11", EnableCommnet=true, Title="t11", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=12, AuthorID=2, CreateTime=dt, State=0, Content="c12", EnableCommnet=true, Title="t12", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=13, AuthorID=3, CreateTime=dt, State=0, Content="c13", EnableCommnet=true, Title="t13", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=14, AuthorID=4, CreateTime=dt, State=0, Content="c14", EnableCommnet=true, Title="t14", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=15, AuthorID=4, CreateTime=dt, State=0, Content="c15", EnableCommnet=true, Title="t15", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=16, AuthorID=5, CreateTime=dt, State=0, Content="c16", EnableCommnet=true, Title="t16", UpCount=0, ViewCount=0, ShowOrder=0},
                new Article(){ ID=17, AuthorID=5, CreateTime=dt, State=0, Content="c17", EnableCommnet=true, Title="t17", UpCount=0, ViewCount=0, ShowOrder=0}
            };
            articles.ForEach(t => context.Article.Add(t));
            context.SaveChanges();
        }
    }
}
